#pragma once
#include "Defines.hpp"
class TaskInfo {

public:
	TaskInfo();
	~TaskInfo();

	void addWorkDynamicConfig(Common::SyncWorkNodeDynamicConfig* pConfig);
	Common::SyncWorkNodeDynamicConfig* getWorkDynamicConfig(string workNodeId, Common::EWorkNodeType workType);
	void setTaskState(Common::ETaskState taskState);
	void ForceInitTaskState();
	Common::ETaskState getTaskState() { return mTaskState; }
public:

	string mTaskId;
	Master::TaskStartFromCommander mStartTaskConfig;
	//Common::ETaskState mTaskState;

	typedef map<string, Common::SyncWorkNodeDynamicConfig>SyncWorkNodeDynamicConfigMap;
	SyncWorkNodeDynamicConfigMap	 mSyncWorkNodeDynamicConfigMap;
	mutable std::recursive_mutex mSyncWorkNodeDynamicConfigMapLock;

	Common::ETaskState mTaskState;
	//WorkNodeInfoList mWorkNodeList;
};
class TaskManager
{
public:
	typedef map<string, TaskInfo*> TaskInfoMap;
	TaskManager();
	~TaskManager();
	static TaskManager& GetInstance() {
		static TaskManager instance;
		return instance;
	}
	bool setTaskState(string task_id, Common::ETaskState State);
	bool getTaskState(string task_id, Common::ETaskState& State);
	bool addTask(string task_id, Master::TaskStartFromCommander* pTaskConfig);
	bool getTaskWorkJson(string task_id, string workId,string& worldJson, string& workJson);
	bool getTaskWorkConfigItem(string task_id, string workId, Master::ConfigWorkItem& pConfigItem);
	Master::TaskStartFromCommander* getTaskStartFromCommander(string task_id);

	bool addSyncWorkNodeDynamicConfig(Common::SyncWorkNodeDynamicConfig* pConfig);
	bool getSyncWorkNodeDynamicConfig(string task_id,string workNodeId,Common::EWorkNodeType workType, Common::SyncWorkNodeDynamicConfig* pConfig);
protected:
	TaskInfo* getTaskInfo(string taskId);
private:


	void run();
protected:
	TaskInfoMap	mTaskInfoMap;
	mutable std::recursive_mutex mTaskConfigInfoMapLock;

};